package com.ziyun.pop.mall.module.user.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.service.goods.constant.GoodsResult;
import com.service.goods.model.seller.SellerInfoVO;
import com.service.goods.model.seller.SellerListResultDto;
import com.service.goods.model.seller.SubSellerListDto;
import com.utility.JsonUtils;
import com.ziyun.pop.mall.module.user.service.UserAddMerchantService;

/**
 * 个人中心子公司管理
 * @author husong  9.26
 *
 */
@Controller
public class UserAddMerchantController {
	
	private static Logger _log = LoggerFactory.getLogger(UserAddMerchantController.class);
	private static final String MODEL = "/user/subMerchant";
	
	
	@Autowired
	private UserAddMerchantService merchantService;
	
	
	
	/**
	 * 显示子公司列表
	 * @return
	 */
	@GetMapping(MODEL+"/index.do")
	public ModelAndView index(){
		ModelAndView view = new ModelAndView("/user/subMerchant/index.html");
		return view;	
	}
	
	
	/**
	 * 获取当前登录账户的详情
	 * @return
	 */
	@GetMapping(MODEL+"/showMainMerchantInfo.json")
	@ResponseBody
	public GoodsResult<SellerInfoVO> showMainMerchantInfo(){
		return merchantService.getMainSellerInfoVO();
		
	}
	
	/**
	 * 获取子公司列表详情
	 * @return
	 */
	@PostMapping(MODEL+"/getSubMerchantList.json")
	@ResponseBody
	public GoodsResult<SellerListResultDto> showSubMerchantList(String subSellerParam){
		SubSellerListDto subSellerListVo = JsonUtils.string2Object(subSellerParam, SubSellerListDto.class);
		return merchantService.getSubSellerList(subSellerListVo);
		
	}
	
	/**
	 * 展示添加子公司页面
	 * @return
	 */
	@GetMapping(MODEL+"/showMainMerchantInfo.do")
	public ModelAndView showMainMerchant(){
		ModelAndView view = new ModelAndView("/user/subMerchant/addSubMerchant.html");
		return view;		
	}
	
	/**
	 * 新增子公司
	 * @return
	 */
	@PostMapping(MODEL+"/addSubMerchant.json")
	@ResponseBody
	public GoodsResult userAddMerchant(String subSellerData,String verifyCode){
		SellerInfoVO subSellerInfoVo = JsonUtils.string2Object(subSellerData, SellerInfoVO.class);
		GoodsResult addMerchantService = merchantService.addMerchantService(subSellerInfoVo,verifyCode);
		return addMerchantService;
	}

}
